
#include "../lettershell/shell_cpp.h"
#include "cmsis_os.h"
#include "softbus.h"
#include <stdio.h>

namespace ShellCmd
{
    int Mem()
    {
        HeapStats_t stats;

        vPortGetHeapStats(&stats);

        printf("FreeRTOS heap usage:\n");
        printf("  Free: %u\n", stats.xAvailableHeapSpaceInBytes);
        printf("  Minimum free: %u\n", stats.xMinimumEverFreeBytesRemaining);
        putchar('\n');
        printf("  Largest block: %u\n", stats.xSizeOfLargestFreeBlockInBytes);
        printf("  Smallest block: %u\n", stats.xSizeOfSmallestFreeBlockInBytes);

        return true;
    }
} // namespace ShellCmd

// clang-format off
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), mem, ShellCmd::Mem, Get FreeRTOS heap usage);